package org.yray.sip.creator;


import org.yray.sip.base.MsgEle;
import org.yray.sip.server.SipSession;

public class InfoCreator extends MessageCreator {
    /***
     INFO sip:12104@172.40.1.62:5060;transport=udp SIP/2.0
     Via: SIP/2.0/UDP 221.4.130.21:17293;rport;branch=z9hG4bKHX7tgSp3FU4vF
     Max-Forwards: 70
     From: "Outbound Call" <sip:15531170051@172.40.1.190>;tag=Z62rN86tg8j5K
     To: <sip:12104@172.40.1.62:5060>;tag=9vD6v7jH888gm
     Call-ID: 8cad8b23-389f-123a-3781-00505684eff3
     CSeq: 36455140 INFO
     Contact: <sip:mod_sofia@221.4.130.21:17293>
     User-Agent: FreeSWITCH-mod_sofia/1.6.20+git~20180123T214909Z~987c9b9a2a~64bit
     Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY
     Supported: timer, path, replaces
     Content-Type: message/update_display
     Content-Length: 0
     X-FS-Display-Name: Outbound Call
     X-FS-Display-Number: 15531170051
     * @param session
     * @return
     */
    @Override
    public String createMsg(SipSession session){
        StringBuilder sb = new StringBuilder();
        sb.append("INFO sip:"+session.getTo()+"@"+session.getSipIpPort()+" SIP/2.0").append(MsgEle.LINE_SEPARATOR);
        sb.append("Via: SIP/2.0/UDP ").append(session.getLocalIpPort()).append(";rport;branch=").append(session.getBranch()).append(MsgEle.LINE_SEPARATOR);
        sb.append("Max-Forwards: 70").append(MsgEle.LINE_SEPARATOR);
        sb.append("From: "+session.getSipExtIpName()+";tag="+session.getTag()).append(MsgEle.LINE_SEPARATOR);
        sb.append("To: "+session.getToExt()).append(MsgEle.LINE_SEPARATOR);
        sb.append("Contact: "+session.getContact()).append(MsgEle.LINE_SEPARATOR);
        sb.append("Call-ID: "+session.getCallId()).append(MsgEle.LINE_SEPARATOR);
        sb.append("CSeq: "+session.getCseq()+" INFO").append(MsgEle.LINE_SEPARATOR);
        sb.append("Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS").append(MsgEle.LINE_SEPARATOR);
        sb.append("User-Agent: ROBOT NO1").append(MsgEle.LINE_SEPARATOR);
        sb.append("Content-Type: message/update_display").append(MsgEle.LINE_SEPARATOR);
        sb.append("Content-Length: 0").append(MsgEle.LINE_SEPARATOR);
        sb.append(MsgEle.LINE_SEPARATOR);
        return sb.toString();
    }


}
